home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 1833 / 1833.xpi / chrome / m / yoono.com / sidebar.jar / sidebar / js / configWizard.js < prev    next >
Text File  |  2009-12-16  |  15KB  |  1 lines

  1. var pop=null;function Wizard(b,a,c){this.YEXTIF=b.YEXTIF;this.accountCreated=false;this.action=Wizard.prototype.ACTION_LOGIN;this.actionBeforeForgot=Wizard.prototype.ACTION_LOGIN;this.doc=document;this.sidebar=b;this.configPop=a;this.userCredential=c;this._login="";this._password="";this.loginValidationRegExp=new RegExp(/[^a-zA-Z0-9.\-_]/);this.sharedBookmarks=new Object();this.noSync=false;this.maxSharedBkmId=0;this.avatarNeedsUpload=false;this.anonUserId=null;this.userChoice="accept";this.errorLabel=$("error-label");this.errorBox=$("error-box");this.previousErrorElement=null;this.avatarForm=$("wizard-post-avatar-form")}Wizard.prototype.ACTION_CREATE="create";Wizard.prototype.ACTION_LOGIN="login";Wizard.prototype.ACTION_FORGOT="forgot";Wizard.prototype.init=function(){this.serverUrl=this.YEXTIF.execFct("getPref","serverurl");this.linkServerUrl=this.serverUrl+"linkserver";var a=window.location.href;this.rootUrl=a.substr(0,a.lastIndexOf("/"))+"/";this.throbber=new ThrobberCtrl($("wizard-throbber"));this.configPop.popupHelper.checkKey=function(){return}};Wizard.prototype.closingPopup=function(){return(true)};Wizard.prototype.getNoAccount=function(){if(this.userCredential){return(this.userCredential.anonymous)}else{return(true)}};Wizard.prototype.toggleShowPassword=function(b){var f="wizard-create-password";var e=$(f);var c=e.getAttribute("type")||"text";if("text"==c){b.innerHTML=this.translateText("show");if(Prototype.Browser.IE){var d=e.value;var a=e.outerHTML.toString();a=a.replace("INPUT ","INPUT type=password ");e.outerHTML=a;e=$(f);e.value=d;setTimeout(function(){e.focus()},10)}else{e.setAttribute("type","password")}}else{b.innerHTML=this.translateText("hide");if(Prototype.Browser.IE){var d=e.value;var a=e.outerHTML.toString();a=a.replace(" type=password"," type=text");e.outerHTML=a;e=$(f);e.value=d;setTimeout(function(){e.focus()},10)}else{e.setAttribute("type","text")}}};Wizard.prototype.toggleForgotForm=function(){this.undisplayErrors();if(this.action!=Wizard.prototype.ACTION_FORGOT){this.actionBeforeForgot=this.action;this.action=Wizard.prototype.ACTION_FORGOT}else{this.action=this.actionBeforeForgot}yoono.dom.toggleClassName(document.body,"wizard-show-forgot")};Wizard.prototype.showLoginForm=function(){yoono.dom.addClassName(document.body,"wizard-show-wizard");yoono.dom.removeClassName(document.body,"wizard-show-addwidget");yoono.dom.addClassName(document.body,"wizard-show-login");this.action=Wizard.prototype.ACTION_LOGIN;$("wizard-option-login").checked=true};Wizard.prototype.showRegistrationForm=function(a,b){this._yoodgetToBeAdded=a;this._yoodgetButtonToBeAdded=b;yoono.dom.addClassName(document.body,"wizard-show-wizard");yoono.dom.addClassName(document.body,"wizard-show-addwidget");yoono.dom.addClassName(document.body,"wizard-show-create");yoono.dom.removeClassName(document.body,"wizard-show-login");this.action=Wizard.prototype.ACTION_CREATE;$("wizard-option-create").checked=true};Wizard.prototype.closeRegistrationForm=function(a){if(!a){this._yoodgetToBeAdded=null}};Wizard.prototype.setSharedBkms=function(a,b){this.noSync=a;this.sharedBookmarks=b};Wizard.prototype.toggleWizardOption=function(a){this.undisplayErrors();switch(a){case Wizard.prototype.ACTION_CREATE:yoono.dom.addClassName(document.body,"wizard-show-create");yoono.dom.removeClassName(document.body,"wizard-show-login");$("wizard-option-create").checked=true;$("config-resize").style.backgroundColor="transparent";break;case Wizard.prototype.ACTION_LOGIN:yoono.dom.addClassName(document.body,"wizard-show-login");yoono.dom.removeClassName(document.body,"wizard-show-create");$("wizard-option-login").checked=true;$("config-resize").style.backgroundColor="black";break}this.action=a};Wizard.prototype.busyfy=function(){this.undisplayErrors();this.busy=true;this.throbber.play();document.body.style.cursor="wait"};Wizard.prototype.unbusyfy=function(){this.busy=false;this.throbber.stop();document.body.style.cursor="auto"};Wizard.prototype.setChoice=function(b,a){b.firstChild.checked=true;this.userChoice=a};Wizard.prototype.translateText=function(a){return(yoono.localization.translate(a,this.configPop.popupHelper.languages))};Wizard.prototype.displayError=function(a,b){this.errorLabel.innerHTML=this.translateText(a);if(b){yoono.dom.addClassName(b,"error");this.previousErrorElement=b}yoono.dom.show(this.errorBox)};Wizard.prototype.undisplayErrors=function(){yoono.dom.hide(this.errorBox);if(this.previousErrorElement){yoono.dom.removeClassName(this.previousErrorElement,"error")}};Wizard.prototype.toggleUploadAvatar=function(){var a=$("wizard-avatar-upload");if(a.visible()){yoono.dom.hide(a)}else{yoono.dom.show(a)}};Wizard.prototype.updateAvatar=function(a){$("wizard-avatar-img").src="file:///"+a;this.toggleUploadAvatar();this.avatarNeedsUpload=true};Wizard.prototype.validateWizard=function(d){if(this.busy){return}if(d){if(!(Event.KEY_RETURN==d.keyCode)){return}}this.undisplayErrors();try{switch(this.action){case Wizard.prototype.ACTION_FORGOT:var j=$("wizard-forgot-email");var b=this.checkEmailInput(j);if(!b){return}var a=this.serverUrl+"rest/user/"+encodeURIComponent(this.email)+"/sendpassword";this.busyfy();var h=this;YServices.ajax(a,{method:"get",onSuccess:function(e){h.unbusyfy();h.passwordSent(e)},on404:function(e){h.unbusyfy();h.passwordSent(e)},onFailure:function(e){h.unbusyfy();h.requestFailure(e)}});break;case Wizard.prototype.ACTION_LOGIN:var l=$("wizard-login-login");var c=$("wizard-login-password");if(!this.checkLoginInput(l)){return}if(!this.checkPwdInput(c)){return}this._login=l.value;this._password=c.value;var f=this._login+":"+this._password;var i='<server-script version="1.0">\n  <context>\n    <user-id>'+YTools.escapeXML(f)+"</user-id>\n  </context>\n  <get-user-data/>\n</server-script>";var h=this;YServices.ajax(this.linkServerUrl,{method:"post",parameters:"script="+encodeURIComponent(i),onSuccess:function(e){h.checkLoginResult(e)},onFailure:function(e){h.requestFailure(e)}});break;case Wizard.prototype.ACTION_CREATE:var l=$("wizard-create-login");var c=$("wizard-create-password");var k=$("wizard-create-email");if(!this.checkLoginInput(l)){return}if(!this.checkPwdInput(c)){return}if(!this.checkEmailInput(k)){return}this._login=l.value;this._password=c.value;this._email=k.value;this.sidebar.sendRegistrationStat("register");if(this.userCredential&&this.userCredential.anonymous){this.desanonymizeUser()}else{this.createUser(false)}break}}catch(g){this.YEXTIF.logError("Config.validate : login error "+g)}};Wizard.prototype.passwordSent=function(f){var b=false;try{var d=null;if(f.responseXML!=null){d=f.responseXML.documentElement}if(d&&"getAttribute" in d){b=true;var a=d.getAttribute("status");if("OK"==a){this.displayError("An email with the credentials was sent to this address.")}else{this.displayError("This email was not found in our database.")}}}catch(c){this.YEXTIF.logError("Config.passwordSent : "+c)}if(!b){this.requestFailure(f)}};Wizard.prototype.requestFailure=function(a){this.YEXTIF.logDebug("checkLogin:requestFailure");this.displayError("Temporary server error, please try again later.");if(a&&a.responseText){this.YEXTIF.logError("Config.requestFailure : request error "+a.responseText)}};Wizard.prototype.checkLoginResult=function(f){this.unbusyfy();try{if(f.responseXML==null||f.responseXML.documentElement==null){this.requestFailure(f);return}var c=f.responseXML.documentElement;var b=c.getElementsByTagName("user-data");if(!b||!b[0]){this.displayError("Invalid login or password.");return}this.closeRegistrationForm(true);this.logUser(false)}catch(a){this.YEXTIF.logError("Wizard.checkLoginResult:"+a+":"+a.stack)}};Wizard.prototype.createUser=function(b){this.YEXTIF.logDebug("Wizard.createUser : requesting new Id");try{this.busyfy();var d=this.YEXTIF.execFct("getVersion");var c=(Prototype.Browser.IE?"exe":"xpi");var f='<server-script version="1.0">';var g=this.linkServerUrl;if(!b){f+=' <create-user login="'+YTools.escapeXML(this._login)+'" password="'+YTools.escapeXML(this._password)+'" email="'+YTools.escapeXML(this._email)+'"> </create-user>'}else{f+=" <create-anonymous-user></create-anonymous-user>"}f+=" <context><version>"+d+"</version><client>"+c+"</client> </context> </server-script>";var a=this;YServices.ajax(g,{method:"post",parameters:"script="+encodeURIComponent(f),onSuccess:function(e){a.unbusyfy();a.YEXTIF.logDebug("Wizard.createUser response : "+e.responseText);a.handleNewUser(e,b)},onFailure:function(e){a.unbusyfy();a.requestFailure(e)}})}catch(h){this.unbusyfy();this.YEXTIF.logError("Wizard.createUser:"+h)}};Wizard.prototype.desanonymizeUser=function(){this.YEXTIF.logDebug("Wizard.desanonymizeUser : switching to non anonymous user");try{var a=this;this.busyfy();var b='<server-script version="1.0"> <context>  <user-id>'+this.userCredential.userId+'</user-id> </context> <change-login-password login="'+YTools.escapeXML(this._login)+'" password="'+YTools.escapeXML(this._password)+'"/></server-script>';YServices.ajax(this.linkServerUrl,{method:"post",parameters:"script="+encodeURIComponent(b),onSuccess:function(d){this.YEXTIF.logDebug("Wizard.desanonymizeUser : got user : "+d.responseText);a.unbusyfy();a.handleNewUser(d,false)},onFailure:function(d){a.unbusyfy();a.requestFailure(d)}})}catch(c){this.unbusyfy();this.YEXTIF.logError("Wizard.desanonymizeUser:"+c+":"+c.stack)}};Wizard.prototype.handleNewUser=function(i,c){var b=false;try{if(i.responseXML==null||i.responseXML.documentElement==null){this.requestFailure(i)}else{var g=i.responseXML.documentElement;var f=g.getElementsByTagName("display-message");if(f&&f[0]){var a=f[0].getAttribute("code");if("MSG_LOGIN_PASSWORD_CHANGED"==a){b=true;this.sidebar.setKeyValue("ProfileDate",new Date().getTime());this.uploadAvatar()}if("MSG_WELCOME_NEW_USER"==a){this.sidebar.setKeyValue("CreateDate",new Date().getTime());b=true;if(c){var h=g.getElementsByTagName("user-id");if(h&&h[0]){this.userCredential=new Object();this.userCredential.login="";this.userCredential.password="";this.userCredential.anonymous=true;this.userCredential.userId=yoono.dom.XMLHelper.getInnerValue(h[0])}else{this.requestFailure(i);b=false}}else{this.uploadAvatar()}}}else{f=g.getElementsByTagName("display-error");if(f&&f[0]){var a=f[0].getAttribute("code");switch(a){case"ERROR_LOGIN_ALREADY_USED":case"ERROR_INVALID_USER_ID":this.displayError("This login is already taken by another user.",$("wizard-create-login"));break;default:this.requestFailure(i);break}}else{this.requestFailure(i)}}}if(b){this.YEXTIF.execFct("setKeyValue",["wizardCreateDate",new Date().getTime()]);this.logUser(c)}}catch(d){this.YEXTIF.logError("Wizard.handleNewUser:"+d+":"+d.stack);this.requestFailure(i)}};Wizard.prototype.logUser=function(c){var a=false;yoono.dom.removeClassName(document.body,"noaccount");this.closeRegistrationForm(true);this.busyfy();this.YEXTIF.execFct("disableSync");if(!c){yoono.dom.removeClassName(document.body,"anonymous");if(!this.userCredential||this.userCredential.anonymous==true){a=true}if(!this.userCredential){this.userCredential=new Object()}this.userCredential.login=this._login;this.userCredential.password=this._password;this.userCredential.anonymous=false;this.userCredential.userId=this._login+":"+this._password}else{this.noSync=true}this.YEXTIF.execFct("setUserId",this.userCredential.userId);var d="";switch(this.action){case Wizard.prototype.ACTION_LOGIN:accMgrTopic=YServices.accountsManager.YOONO_USER_SIGNED_IN;break;case Wizard.prototype.ACTION_CREATE:accMgrTopic=YServices.accountsManager.YOONO_USER_NEW_REGISTERED;break}YServices.accountsManager.onPostLoginInit(accMgrTopic,this.userCredential);if(this._yoodgetToBeAdded){var b=this.configPop.addYoodgetToSidebar(this._yoodgetToBeAdded,this._yoodgetButtonToBeAdded)}this.sidebar.signIn_enableSidebar_callback(false);this.unbusyfy();this.wizardComplete()};Wizard.prototype.notifyEndSync=function(){this.unbusyfy();try{var c=null;var g=false;var b='<server-script version="1.0"> <context>  <user-id>'+YTools.escapeXML(this._login+":"+this._password)+"</user-id> </context>\n";for(var f in this.sharedBookmarks){c=this.sharedBookmarks[f];if(c.shared!=c.alreadyShared){g=true;if(c.shared){this.YEXTIF.logDebug("Folder "+f+" must now be shared");this.maxSharedBkmId++;b=b+'<add-xlink ref=":'+this.maxSharedBkmId+'" path="/$pub/'+this.maxSharedBkmId+'"/><update-link><old-link path="'+f+'"/><new-link path="'+f+'" id="'+this.maxSharedBkmId+'"/>\n</update-link>'}else{this.YEXTIF.logDebug("Folder "+f+" must no longer be shared");b=b+'<remove-xlink ref=":'+c.id+'" path="/$pub/'+c.id+'"/><update-link><new-link path="'+f+'"/><old-link path="'+f+'" id="'+c.id+'"/>\n</update-link>'}}}if(!g){this.wizardComplete();return}b+="</server-script>";var a=this;this.busyfy();YServices.ajax(this.linkServerUrl,{method:"post",parameters:"script="+encodeURIComponent(b),onSuccess:function(e){a.unbusyfy();this.YEXTIF.logDebug("Wizard.notifyEndSync share settings response : "+e.responseText);a.wizardComplete()},onFailure:function(e){a.unbusyfy();a.requestFailure(e)}})}catch(d){this.unbusyfy();this.displayError("Temporary server error, please try again later.");this.YEXTIF.logError("Wizard.notifyEndSync : "+d)}};Wizard.prototype.uploadAvatar=function(){if(this.avatarNeedsUpload){$("wizard-avatar-upload-userid").value=this._login+":"+this._password;this.avatarForm.submit()}};Wizard.prototype.wizardComplete=function(){yoono.dom.addClassName(document.body,"wizard-done");$("wizard-done-username").innerHTML=this._login;var a=this;setTimeout(function(){$("wizard-done-avatar").src="http://api.yoono.com/avatar/nickname/"+encodeURIComponent(a._login)},400);this.sidebar.userConnected()};Wizard.prototype.checkLoginInput=function(c){var a=c.value.strip();var b=true;if(a.length<6){this.displayError("Login length must be between 6 and 20 characters.",c);b=false}if(a.length>20){this.displayError("Login length must be between 6 and 20 characters.",c);b=false}if(this.loginValidationRegExp.test(a)){this.displayError("Login must be composed of letters, digits, dash, underscore and dot only.",c);b=false}this.login=a;return(b)};Wizard.prototype.checkPwdInput=function(c){var b=c.value.strip();var a=true;if(b.length<6){this.displayError("Password length must be between 6 and 20 characters.");a=false}if(b.length>20){this.displayError("Password length must be between 6 and 20 characters.");a=false}if(this.loginValidationRegExp.test(b)){this.displayError("Password must be composed of letters, digits, dash, underscore and dot only.");a=false}if(!a){yoono.dom.addClassName(c,"bad-input")}this.pwd=b;return(a)};Wizard.prototype.checkEmailInput=function(c){var b=c.value.strip();var a=YTools.checkEmailSyntax(b);if(!a){this.displayError("Please type a valid email address",c)}this.email=b;return(a)};